# To change this template, choose Tools | Templates
# and open the template in the editor.

from hexconfig import *
import pygame
from edgeDictionary import *

pygame.init()

clock = pygame.time.Clock()

print "Loading autosaveEdges.pkl"
loadFile = open("../ai_data/autosaveEdges.pkl",'rb')
print "..."
oldEdges = pickle.load(loadFile)
print "Done loading file!"

newEdges = edgeDictionary()

edgeNumber = 0
printStep = .5
nextPercent = 0.00001
lastMilliseconds = clock.tick()
print "Starting to convert edges:"
oldKeys = oldEdges.keys()
for oldKey in oldKeys:

    newEdges[oldKey] = oldEdges[oldKey]
    edgeNumber += 1
    percent = (1.0*edgeNumber)/(1.0*len(oldKeys))*100.0
    if percent >= nextPercent:
        print edgeNumber, "edges,",percent, "%",
        ms = clock.tick()-lastMilliseconds
        lastMilliseconds = clock.tick()
        secs = ms/1000
        mins = secs/60
        print mins," mins,",secs%60 if secs>60 else secs," secs"
        
        nextPercent += printStep
print "Done converting edges"
p = pickle.Pickler(open("../ai_data/newEdgeDictionary.pkl",'wb'))
p.fast = True
print "Starting to save newEdgeDictionary.pkl"
p.dump(newEdges)
print "Done saving file!"